package com.feiyu.universal.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feiyu.common.controller.BaseController;
import com.feiyu.universal.entity.Dict;
import com.feiyu.universal.service.DictService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tang ming
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/dict")
@AllArgsConstructor
public class DictController extends BaseController<DictService,Dict> {

    private DictService dictService;

    @GetMapping("/detail/{id}")
    public R<Dict> detail(@PathVariable int id){
        return R.data(dictService.getById(id));
    }

    @GetMapping("/list/{id}")
    public R<List<Dict>> list(@PathVariable("id") int id,String code){
        QueryWrapper<Dict> wrapper = new QueryWrapper<>();
        wrapper.eq("parentId",id);
        if (code!=null&&code.length()>0)
            wrapper.eq("code",code);
        return R.data(dictService.list(wrapper));
    }
    @GetMapping("/listLeaf")
    public R<List<Dict>> listLeaf(int id,String code){
        return R.data(dictService.listAllLeaf(id,code));
    }
}

